package com.chenqi.config;

import com.chenqi.interceptor.CorsInterceptor;
import com.chenqi.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @description: web相关的配置类
 * @program: ardaicommunity
 * @author: ChenQi
 * @create: 2021-03-2021/3/8-12-01
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Bean
    public CorsInterceptor getCorsInterceptor(){
        return new CorsInterceptor();
    }

    @Bean
    public LoginInterceptor getLoginInterceptor() {
        return new LoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册跨域拦截器
        registry.addInterceptor(getCorsInterceptor()).addPathPatterns("/**");
        //注册登陆拦截器
        registry.addInterceptor(getLoginInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/api/v1/user/login","/api/v1/user/register", "/api/v1/billboard/get", "/api/v1/promotion/list", "/api/v1/tip/today","/api/v1/post/list/**","/api/v1/post/detail/**","/api/v1/post/addPost","/api/v1/post/recommend","/api/v1/comment/list/**")
                .excludePathPatterns("/api/v1/comment/addComment","/api/v1/post/remove/**","/api/v1/post/search/**","/api/v1/post/userPost/**");
    }
}
